package com.wy.aopproxy;

import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;

/**
 * 类名 Test
 * 功能描述 Test
 * 开发人 王勇
 * 创建日期 2023-10-27 15:59
 * 负责人 王勇
 * 交接时间 2023-10-27
 */
public class TestMain {
    public static void main(String[] args) {
        // 原始对象
        TestService testService = new TestService();

        // 准备切点
        JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
        pointcut.setPattern("com.wy.aopproxy.TestService.*");

        // 准备通知
        TestMethodInterceptor interceptor = new TestMethodInterceptor();

        // 切面 = 切点 + 通知
        Advisor advisor = new DefaultPointcutAdvisor(pointcut, interceptor);

        // 代理工厂
        ProxyFactory factory = new ProxyFactory();
        // 添加切面
        factory.addAdvisor(advisor);
        // 设置被代理的对象
        factory.setTarget(testService);

        TestService proxy = (TestService)factory.getProxy();
        proxy.hello();
    }
}
